﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geodatabase;
using PlanningGIS.DataConvert.model;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.esriSystem;
using System.IO;
using ESRI.ArcGIS.DataSourcesGDB;
using Microsoft.VisualBasic;
using ESRI.ArcGIS.Geometry;
using System.Runtime.InteropServices;
using PlanningGIS.Framework;
using PlanningGIS.Framework.Controls;

using DevComponents.DotNetBar;
using PlanningGIS.ArcGIS.Custom;
using PlanningGIS.Engine.Controls;
using PlanningGIS.Win.Controls;
using PlanningGIS.Util.Log;

namespace PlanningGIS.DataConvert.form
{
    /// <summary>
    /// 名    称：FrmDlgDataConvert
    /// 作    用：矢量数据格式转换对话框
    /// 开发人员：张利勇
    /// 开发日期：2009-10-28
    /// 修改人员：
    /// 修改日期：
    /// 修改说明：由于FME对MicroStation V8 格式支持不够好，导出时将导出到Default Model中，不是Untitled Design Model,这点要注意
    /// </summary>
    public partial class FrmDlgDataConvert : Office2007Form
    {
        List<string> pFeatClsList = new List<string>();
        List<string> pFeatDsList = new List<string>();
        private OpenDataDialog openDataDialog1 = new OpenDataDialog();
        private List<IDataNode> m_DataNodes; //用户选中的数据源
        
        static string CADFileVersion = "2007";
        static string CADTemplateFile = "";
        IApplication m_Application = null;
        public CmdSelectDataOk SelectDataOk;
        //private List<WORKSPACETYPE> esriDatasetTypeFilters;
        public IApplication Application
        {
            get { return m_Application; }
            set { m_Application = value; }
        }

        public FrmDlgDataConvert(IApplication value)
        {
            InitializeComponent();

            m_Application = value;
        }

        /// <summary>
        /// 选择文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenTargetWS_Click(object sender, EventArgs e)
        {
            switch (combo_SaveFormat.SelectedIndex)
            {
                case 0://gdb
                case 1://mdb  
                case 4://dwg
                case 5://dgn
                    {
                        saveFileExport.Title = "指定目标文件";
                        if (combo_SaveFormat.SelectedIndex == 0)
                        {
                            saveFileExport.Filter = "File Geodatabase (*.gdb)| *.gdb";
                            if (saveFileExport.ShowDialog() == DialogResult.OK)
                            {
                                if (saveFileExport.FileName.EndsWith(".gdb", true, System.Globalization.CultureInfo.CurrentCulture) == false)
                                {
                                    MsgHelper.ShowWarningMsgbox("输出路径必须以.gdb结尾，请重新输入路径！");
                                }
                                else
                                {
                                    txtExportPath.Text = saveFileExport.FileName;
                                }
                            }
                        }
                        else if (combo_SaveFormat.SelectedIndex == 1)
                        {
                            saveFileExport.Filter = "Personal Geodatabase(*.mdb) | *.mdb";
                            if (saveFileExport.ShowDialog() == DialogResult.OK)
                            {
                                txtExportPath.Text = saveFileExport.FileName;
                            }
                        }
                        else if (combo_SaveFormat.SelectedIndex == 4)
                        {
                            saveFileExport.Filter = "AutoCAD DWG数据(*.dwg)|*.dwg|AutoCAD DXF数据(*.dxf)|*.dxf";
                            if (saveFileExport.ShowDialog() == DialogResult.OK)
                            {
                                txtExportPath.Text = saveFileExport.FileName;                                
                            }
                        }
                        else if (combo_SaveFormat.SelectedIndex == 5)
                        {
                            saveFileExport.Filter = "MicroStation DGN数据(*.dgn)|*.dgn";
                            if (saveFileExport.ShowDialog() == DialogResult.OK)
                            {
                                txtExportPath.Text = saveFileExport.FileName;
                            }
                        }
                        break;
                    }
                case 2://shp
                case 3://mif
                    {
                        FolderBrowserDialog fbdlg = new FolderBrowserDialog();
                        fbdlg.ShowNewFolderButton = true;
                        fbdlg.Description = "选择转换路径";
                        if (fbdlg.ShowDialog() == DialogResult.OK)
                        {
                            txtExportPath.Text = fbdlg.SelectedPath + "\\";
                        }
                        break;
                    }

                default:
                    {
                        break;
                    }
            }            
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            #region 条件判断

            if (pFeatClsList.Count + pFeatDsList.Count == 0)
            {
                MsgHelper.ShowWarningMsgbox("请选择矢量数据");
                return;
            }

            if (txtExportPath.Text == "")
            {
                MsgHelper.ShowWarningMsgbox("请选择保存路径！");
                return;
            }

            if (txtExportPath.Text.EndsWith(".gdb", true, System.Globalization.CultureInfo.CurrentCulture))
            {
                if (Directory.Exists(txtExportPath.Text))
                {
                    MsgHelper.ShowWarningMsgbox("文件" + txtExportPath.Text + "已存在，请重新选择输出文件。");
                    return;
                }
            }
            else
            {
                if (File.Exists(txtExportPath.Text))
                {
                    MsgHelper.ShowWarningMsgbox("文件" + txtExportPath.Text + "已存在，请重新选择输出文件。");
                    return;
                }
            }

            #endregion

            try
            {
                string TargetDataset;
                btnCancel.Visible = true;

                #region 判断转换数据的类型

                TargetDataset = txtExportPath.Text;
                if (pFeatDsList.Count > 0)
                {
                    ImportFeatureDatasetList(pFeatDsList, TargetDataset);
                }

                if (pFeatClsList.Count > 0)
                {
                    ExportFeatClsList(pFeatClsList, TargetDataset);
                }

                #endregion
            }
            catch (Exception ex)
            {
                MsgHelper.ShowWarningMsgbox("转换失败！" + ex.Message);
                LogHelper.WriteLog("转换失败！" + ex.Message, zjgisLogType.zjgisLogError);
            }
            finally
            {
                string strSdeFile = System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location) + "\\tempconvert.sde";
                if (File.Exists(strSdeFile))
                {
                    File.Delete(strSdeFile);
                }
            }
        }

        /// <summary>
        /// 采用GP工具QuickExport，将pFeatClsList转换到strTargetFileName中
        /// </summary>
        /// <param name="pFeatClsList"></param>
        /// <param name="strTargetFileName"></param>
        private void ExportFeatClsList(List<string> pFeatClsList, string strTargetFileName)
        {
            try
            {
                if (pFeatClsList.Count == 0) return;

                this.Cursor = Cursors.WaitCursor;

                ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                GP.OverwriteOutput = true;
                GP.AddOutputsToMap = false;
                GP.LogHistory = true;

                ESRI.ArcGIS.DataInteroperabilityTools.QuickExport pQuickEpTool = new ESRI.ArcGIS.DataInteroperabilityTools.QuickExport();
                if (strTargetFileName.Contains(" "))
                {
                    strTargetFileName = "\"" + strTargetFileName + "\"";
                }
                pQuickEpTool.Output = strTargetFileName;
                if (combo_SaveFormat.SelectedIndex == 4)
                {
                    //QuickExport D:\dxh.gdb\DLG_500\RES_LN;D:\dxh.gdb\DLG_500\PIP_PT;D:\dxh.gdb\DLG_500\PIP_LN;D:\h51g058012.dgn\Polygon ACAD,E:\bbcad.dwg,"RUNTIME_MACROS,""_ATTRKIND,extended_entity_data,_REL,Release2007,_TMPL,E:\C网光缆图.dwg"",META_MACROS,""Dest_ATTRKIND,extended_entity_data,Dest_REL,Release2007,Dest_TMPL,E:\C网光缆图.dwg"",METAFILE,ACAD,COORDSYS,,__FME_DATASET_IS_SOURCE__,false"
                    string strCADVersion, strTMPL = "", Dest_TMPL = "";
                    if (CADFileVersion.ToUpper().StartsWith("R"))
                    {
                        strCADVersion = "Release" + CADFileVersion.Substring(1);
                    }
                    else
                    {
                        strCADVersion = "Release" + CADFileVersion;
                    }

                    if (CADTemplateFile.Length > 0)
                    {
                        strTMPL = ",_TMPL," + CADTemplateFile;
                        Dest_TMPL = ",Dest_TMPL," + CADTemplateFile;
                    }
                    pQuickEpTool.Output = "ACAD," + strTargetFileName + ",\"RUNTIME_MACROS,\"\"_ATTRKIND,extended_entity_data,_REL," + strCADVersion + strTMPL + "\"\",META_MACROS,\"\"Dest_ATTRKIND,extended_entity_data,Dest_REL," + strCADVersion + Dest_TMPL + "\"\",METAFILE,ACAD,COORDSYS,,__FME_DATASET_IS_SOURCE__,false\"";
                }
                else if (combo_SaveFormat.SelectedIndex == 5)
                {
                    //QuickExport E:\bb.mdb\水网线 IGDS,D:\aaa.dgn,"RUNTIME_MACROS,""_TYPE3,yes,_ALLOW_FILL,yes,_OUT_UNITS,IGDS_MASTER_UNITS,
                    //_SEED,""""C:\Program Files\ArcGIS\Data Interoperability Extension\design\seed3d_m_v8.dgn"""",WRITING_TO_V8,YES,_COMPUTE_SEED,no"",META_MACROS,""Dest_TYPE3,yes,Dest_ALLOW_FILL,yes,Dest_OUT_UNITS,IGDS_MASTER_UNITS,
                    //Dest_SEED,""""C:\Program Files\ArcGIS\Data Interoperability Extension\design\seed3d_m_v8.dgn"""",DestWRITING_TO_V8,YES,Dest_COMPUTE_SEED,no"",METAFILE,dgnv8,COORDSYS,,__FME_DATASET_IS_SOURCE__,false"
                    //QuickExport D:\work\ss8.gdb\HYD_NET_LN_C;D:\work\ss8.gdb\HYD_BRM_LN_C;D:\work\ss8.gdb\HYD_AUX_LN_C IGDS,D:\work\aaa.dgn,"RUNTIME_MACROS,""_TYPE3,yes,_ALLOW_FILL,yes,_OUT_UNITS,IGDS_MASTER_UNITS,_SEED,""""C:\Program Files\ArcGIS\Data Interoperability Extension\design\seed3d_m_v8.dgn"""",WRITING_TO_V8,YES,_COMPUTE_SEED,no"",META_MACROS,""Dest_TYPE3,yes,Dest_ALLOW_FILL,yes,Dest_OUT_UNITS,IGDS_MASTER_UNITS,Dest_SEED,""""C:\Program Files\ArcGIS\Data Interoperability Extension\design\seed3d_m_v8.dgn"""",DestWRITING_TO_V8,YES,Dest_COMPUTE_SEED,no"",METAFILE,dgnv8,COORDSYS,,__FME_DATASET_IS_SOURCE__,false"

                    string strTMPL = "", Dest_TMPL = "";
                    if (CADTemplateFile.Length > 0)
                    {
                        strTMPL = ",_SEED,\"\"\"\"" + CADTemplateFile + "\"\"\"\"";
                        Dest_TMPL = ",Dest_SEED,\"\"\"\"" + CADTemplateFile + "\"\"\"\"";
                        pQuickEpTool.Output = "IGDS," + strTargetFileName + ",\"RUNTIME_MACROS,\"\"_TYPE3,yes,_ALLOW_FILL,yes,_OUT_UNITS,IGDS_MASTER_UNITS" + strTMPL
                        + ",WRITING_TO_V8,YES,_COMPUTE_SEED,no\"\",META_MACROS,\"\"Dest_TYPE3,yes,Dest_ALLOW_FILL,yes,Dest_OUT_UNITS,IGDS_MASTER_UNITS" + Dest_TMPL
                        + ",DestWRITING_TO_V8,YES,Dest_COMPUTE_SEED,no\"\",METAFILE,dgnv8,COORDSYS,,__FME_DATASET_IS_SOURCE__,false\"";
                    }
                    else
                    {
                        pQuickEpTool.Output = "IGDS," + strTargetFileName + ",\"RUNTIME_MACROS,\"\"_TYPE3,yes,_ALLOW_FILL,yes,_OUT_UNITS,IGDS_MASTER_UNITS,_SEED,\"\"\"\"C:\\Program Files\\ArcGIS\\Data Interoperability Extension\\design\\seed3d_m_v8.dgn\"\"\"\",WRITING_TO_V8,YES,_COMPUTE_SEED,no\"\",META_MACROS,\"\"Dest_TYPE3,yes,Dest_ALLOW_FILL,yes,Dest_OUT_UNITS,IGDS_MASTER_UNITS,Dest_SEED,\"\"\"\"C:\\Program Files\\ArcGIS\\Data Interoperability Extension\\design\\seed3d_m_v8.dgn\"\"\"\",DestWRITING_TO_V8,YES,Dest_COMPUTE_SEED,no\"\",METAFILE,dgnv8,COORDSYS,,__FME_DATASET_IS_SOURCE__,false\"";
                    }
                }
                else if (combo_SaveFormat.SelectedIndex == 0)
                {
                    pQuickEpTool.Output = "GEODATABASE_FILE," + strTargetFileName;
                }
                else if (combo_SaveFormat.SelectedIndex == 1)
                {
                    pQuickEpTool.Output = "GEODATABASE_MDB," + strTargetFileName;
                }
                else if (combo_SaveFormat.SelectedIndex == 2)
                {
                    pQuickEpTool.Output = "SHAPE," + strTargetFileName;
                }
                else if (combo_SaveFormat.SelectedIndex == 3)
                {
                    pQuickEpTool.Output = "MIF," + strTargetFileName;
                }

                //QuickExport E:\DivideFiles\mdb.gdb\黄岩区行政村;E:\DivideFiles\mdb.gdb\路桥区行政村 GEODATABASE_FILE,D:\work\sss.gdb
                //QuickExport E:\绍兴测试数据\DLG_10000\232-570.dwg\Polyline;E:\绍兴测试数据\DLG_10000\232-570.dwg\Polygon;E:\绍兴测试数据\DLG_10000\232-570.dwg\Point;E:\绍兴测试数据\DLG_10000\232-570.dwg\MultiPatch;E:\绍兴测试数据\DLG_10000\232-570.dwg\Annotation
                StringBuilder FeatClsInput = new StringBuilder("");
                for (int i = 0; i < pFeatClsList.Count; i++)
                {
                    FeatClsInput.Append(pFeatClsList[i] + ";");
                }
                FeatClsInput.Remove(FeatClsInput.Length - 1, 1);
                pQuickEpTool.Input = FeatClsInput.ToString();
                
                bool bln = RunTool(GP, pQuickEpTool, null);
                if (bln)
                {
                    for (int i = 0; i < pFeatClsList.Count; i++)
                    {
                        LogHelper.WriteLog("数据：" + pFeatClsList[i] + " 转换成功!");
                    }
                    MsgHelper.ShowInfomationMsgbox("数据转换成功!");
                }
                else
                {
                    for (int i = 0; i < pFeatClsList.Count; i++)
                    {
                        LogHelper.WriteLog("数据：" + pFeatClsList[i] + " 转换失败!");
                    }
                    MsgHelper.ShowInfomationMsgbox("数据转换失败!");
                }
            }
            catch (System.Exception ex)
            {
                MsgHelper.ShowErrorMsgbox("转换失败:" + ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        /// <summary>
        /// 导入FeatureDataset到GDB中
        /// </summary>
        /// <param name="pFeatDsList"></param>
        /// <param name="strTargetFileName"></param>
        private void ImportFeatureDatasetList(List<string> pFeatDsList, string strTargetFileName)
        {
            try
            {
                if (pFeatDsList.Count == 0) return;

                this.Cursor = Cursors.WaitCursor;

                ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                GP.OverwriteOutput = true;
                GP.AddOutputsToMap = false;
                GP.LogHistory = true;

                ESRI.ArcGIS.DataInteroperabilityTools.QuickImport pQuickImportTool = new ESRI.ArcGIS.DataInteroperabilityTools.QuickImport();
                pQuickImportTool.Output = strTargetFileName;

                StringBuilder strFeatDsPath = new StringBuilder("");
                if (pFeatDsList[0].EndsWith(".dwg") || pFeatDsList[0].EndsWith(".dxf"))
                {
                    //QuickImport_interop ACAD,E:\绍兴测试数据\DLG_10000\232-580.dwg,"RUNTIME_MACROS,""METAFILE,acad,_EXPAND_BLOCKS,yes,ACAD_IN_USE_BLOCK_HEADER_LAYER,yes,ACAD_IN_RESOLVE_ENTITY_COLOR,yes,_EXPAND_VISIBLE,yes,_READ_AS_2_5D,no,_BULGES_AS_ARCS,no,_STORE_BULGE_INFO,no,_READ_PAPER_SPACE,no,ACAD_IN_READ_GROUPS,no,_IGNORE_UCS,no,_ACADPreserveComplexHatches,no,_EXTRA_DATASETS,""""E:\绍兴测试数据\DLG_10000\232-570.dwg,E:\绍兴测试数据\DLG_10000\232-575.dwg"""",_MERGE_SCHEMAS,YES"",META_MACROS,""Source_EXPAND_BLOCKS,yes,SourceACAD_IN_USE_BLOCK_HEADER_LAYER,yes,SourceACAD_IN_RESOLVE_ENTITY_COLOR,yes,Source_EXPAND_VISIBLE,yes,Source_READ_AS_2_5D,no,Source_BULGES_AS_ARCS,no,Source_STORE_BULGE_INFO,no,Source_READ_PAPER_SPACE,no,SourceACAD_IN_READ_GROUPS,no,Source_IGNORE_UCS,no,Source_ACADPreserveComplexHatches,no"",METAFILE,acad,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" E:\shape\aaa
                    //QuickImport ACAD,"D:\Program Files\规划信息中心\C网光缆图.dwg","RUNTIME_MACROS,""METAFILE,acad,_EXPAND_BLOCKS,yes,ACAD_IN_USE_BLOCK_HEADER_LAYER,yes,ACAD_IN_RESOLVE_ENTITY_COLOR,yes,_EXPAND_VISIBLE,yes,_READ_AS_2_5D,no,_BULGES_AS_ARCS,no,_STORE_BULGE_INFO,no,_READ_PAPER_SPACE,no,ACAD_IN_READ_GROUPS,no,_IGNORE_UCS,no,_ACADPreserveComplexHatches,no,_EXTRA_DATASETS,""""""""""""D:\Program Files\规划信息中心\复件 C网光缆图.dwg"""""""""""",_MERGE_SCHEMAS,YES"",META_MACROS,""Source_EXPAND_BLOCKS,yes,SourceACAD_IN_USE_BLOCK_HEADER_LAYER,yes,SourceACAD_IN_RESOLVE_ENTITY_COLOR,yes,Source_EXPAND_VISIBLE,yes,Source_READ_AS_2_5D,no,Source_BULGES_AS_ARCS,no,Source_STORE_BULGE_INFO,no,Source_READ_PAPER_SPACE,no,SourceACAD_IN_READ_GROUPS,no,Source_IGNORE_UCS,no,Source_ACADPreserveComplexHatches,no"",METAFILE,acad,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" "D:\Program Files\规划信息中心\C网光缆图.gdb"
                    if (pFeatDsList[0].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                    {
                        strFeatDsPath.Append("ACAD,\"" + pFeatDsList[0] + "\"");
                    }
                    else
                    {
                        strFeatDsPath.Append("ACAD," + pFeatDsList[0]);
                    }

                    strFeatDsPath.Append(",\"RUNTIME_MACROS,\"\"METAFILE,acad,_EXPAND_BLOCKS,yes,ACAD_IN_USE_BLOCK_HEADER_LAYER,yes,ACAD_IN_RESOLVE_ENTITY_COLOR,yes,_EXPAND_VISIBLE,yes,_READ_AS_2_5D,no,_BULGES_AS_ARCS,no,_STORE_BULGE_INFO,no,_READ_PAPER_SPACE,no,ACAD_IN_READ_GROUPS,no,_IGNORE_UCS,no,_ACADPreserveComplexHatches,no,");

                    if (pFeatDsList.Count > 1)
                    {
                        strFeatDsPath.Append("_EXTRA_DATASETS,\"\"\"\"");

                        for (int i = 1; i < pFeatDsList.Count; i++)
                        {
                            if (pFeatDsList[i].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                            {
                                strFeatDsPath.Append("\"\"\"\"\"\"\"\"" + pFeatDsList[i] + "\"\"\"\"\"\"\"\"");
                            }
                            else
                            {
                                strFeatDsPath.Append(pFeatDsList[i]);
                            }

                            if (i < pFeatDsList.Count - 1)
                            {
                                strFeatDsPath.Append(",");
                            }
                        }
                        strFeatDsPath.Append("\"\"\"\",");
                    }

                    strFeatDsPath.Append("_MERGE_SCHEMAS,YES\"\",META_MACROS,\"\"Source_EXPAND_BLOCKS,yes,SourceACAD_IN_USE_BLOCK_HEADER_LAYER,yes,SourceACAD_IN_RESOLVE_ENTITY_COLOR,yes,Source_EXPAND_VISIBLE,yes,Source_READ_AS_2_5D,no,Source_BULGES_AS_ARCS,no,Source_STORE_BULGE_INFO,no,Source_READ_PAPER_SPACE,no,SourceACAD_IN_READ_GROUPS,no,Source_IGNORE_UCS,no,Source_ACADPreserveComplexHatches,no\"\",METAFILE,acad,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true\"");
                }
                else if (pFeatDsList[0].EndsWith(".dgn"))
                {
                    //可惜我用ArcToolBox自带的QuickImport工具将dgn转gdb，一直没有成功，可能是FME只支持MS J版本的dgn吧，张利勇
                    //QuickImport IGDS,D:\h51g093011.dgn,"RUNTIME_MACROS,""_IGDS_MSLINKS,no,_IGDS_FRAMME,no,_XPNDCELL,no,_PRESERVE_CELL_INSERTS,no,EXPAND_UNNAMED_CELLS,yes,PRESERVE_UNNAMEDCELL_INSERTS,yes,EXPLODE_DIMENSION_ELEM,yes,SPLIT_MULTITEXT,no,_TEXTTAGS,no,_IN_UNITS,IGDS_MASTER_UNITS,METAFILE,design,_USE_LEVEL_NAMES,no,READ_XREF_FILES,no,USE_XREF_PARENT_MODEL,no,READ_XREF_UPTO_FIRST_LVL,no,_MERGE_SCHEMAS,YES"",META_MACROS,""Source_IGDS_MSLINKS,no,Source_IGDS_FRAMME,no,Source_XPNDCELL,no,Source_PRESERVE_CELL_INSERTS,no,SourceEXPAND_UNNAMED_CELLS,yes,SourcePRESERVE_UNNAMEDCELL_INSERTS,yes,SourceEXPLODE_DIMENSION_ELEM,yes,SourceSPLIT_MULTITEXT,no,Source_TEXTTAGS,no,Source_IN_UNITS,IGDS_MASTER_UNITS,Source_USE_LEVEL_NAMES,no,SourceREAD_XREF_FILES,no,SourceUSE_XREF_PARENT_MODEL,no,SourceREAD_XREF_UPTO_FIRST_LVL,no"",METAFILE,design,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" D:\dxh\gg.gdb
                    if (pFeatDsList[0].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                    {
                        strFeatDsPath.Append("IGDS,\"" + pFeatDsList[0] + "\"");
                    }
                    else
                    {
                        strFeatDsPath.Append("IGDS," + pFeatDsList[0]);
                    }
                    strFeatDsPath.Append(",\"RUNTIME_MACROS,\"\"_IGDS_MSLINKS,no,_IGDS_FRAMME,no,_XPNDCELL,no,_PRESERVE_CELL_INSERTS,no,EXPAND_UNNAMED_CELLS,yes,PRESERVE_UNNAMEDCELL_INSERTS,yes,EXPLODE_DIMENSION_ELEM,yes,SPLIT_MULTITEXT,no,_TEXTTAGS,no,_IN_UNITS,IGDS_MASTER_UNITS,METAFILE,design,_USE_LEVEL_NAMES,no,READ_XREF_FILES,no,USE_XREF_PARENT_MODEL,no,READ_XREF_UPTO_FIRST_LVL,no,_MERGE_SCHEMAS,YES\"\",META_MACROS,\"\"Source_IGDS_MSLINKS,no,Source_IGDS_FRAMME,no,Source_XPNDCELL,no,Source_PRESERVE_CELL_INSERTS,no,SourceEXPAND_UNNAMED_CELLS,yes,SourcePRESERVE_UNNAMEDCELL_INSERTS,yes,SourceEXPLODE_DIMENSION_ELEM,yes,SourceSPLIT_MULTITEXT,no,Source_TEXTTAGS,no,Source_IN_UNITS,IGDS_MASTER_UNITS,Source_USE_LEVEL_NAMES,no,SourceREAD_XREF_FILES,no,SourceUSE_XREF_PARENT_MODEL,no,SourceREAD_XREF_UPTO_FIRST_LVL,no\"\",METAFILE,design,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true\"");
                }
                else if (pFeatDsList[0].EndsWith(".mif"))
                {
                    //QuickImport MIF,"D:\Program Files\规划信息中心\Export_Output_2.mif","RUNTIME_MACROS,""_EXTRA_DATASETS,""""""""""""D:\Program Files\规划信息中心\Export_Output_3.mif"""""""",""""""""D:\Program Files\规划信息中心\Export_Output_4.mif"""""""""""",_MERGE_SCHEMAS,YES"",META_MACROS,,METAFILE,MIF,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" "D:\Program Files\规划信息中心\Export_3.gdb"
                    //QuickImport MIF,"D:\Program Files\规划信息中心\Export_Output_2.mif","RUNTIME_MACROS,""_EXTRA_DATASETS,""""""""""""D:\Program Files\规划信息中心\Export_Output_3.mif"""""""""""",_MERGE_SCHEMAS,YES"",META_MACROS,,METAFILE,MIF,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" "D:\Program Files\规划信息中心\Export_2.gdb"
                    //QuickImport MIF,E:\DivideFiles\Export_Output_2.mif,"RUNTIME_MACROS,""_EXTRA_DATASETS,""""E:\DivideFiles\Export_Output_3.mif,E:\DivideFiles\Export_Output_4.mif"""",_MERGE_SCHEMAS,YES"",META_MACROS,,METAFILE,MIF,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" E:\DivideFiles\Export_Output_2.gdb
                    if (pFeatDsList[0].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                    {
                        strFeatDsPath.Append("MIF,\"" + pFeatDsList[0] + "\"");
                    }
                    else
                    {
                        strFeatDsPath.Append("MIF," + pFeatDsList[0]);
                    }

                    strFeatDsPath.Append(",\"RUNTIME_MACROS,\"\"");

                    if (pFeatDsList.Count > 1)
                    {
                        strFeatDsPath.Append("_EXTRA_DATASETS,\"\"\"\"");

                        for (int i = 1; i < pFeatDsList.Count; i++)
                        {
                            if (pFeatDsList[i].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                            {
                                strFeatDsPath.Append("\"\"\"\"\"\"\"\"" + pFeatDsList[i] + "\"\"\"\"\"\"\"\"");
                            }
                            else
                            {
                                strFeatDsPath.Append(pFeatDsList[i]);
                            }

                            if (i < pFeatDsList.Count - 1)
                            {
                                strFeatDsPath.Append(",");
                            }
                        }
                        strFeatDsPath.Append("\"\"\"\",");
                    }

                    strFeatDsPath.Append("_MERGE_SCHEMAS,YES\"\",META_MACROS,,METAFILE,MIF,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true\"");
                }
                else if (pFeatDsList[0].EndsWith(".gdb"))
                {
                    if (pFeatDsList[0].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                    {
                        strFeatDsPath.Append("GEODATABASE_FILE,\"" + pFeatDsList[0] + "\"");
                    }
                    else
                    {
                        strFeatDsPath.Append("GEODATABASE_FILE," + pFeatDsList[0]);
                    }

                    strFeatDsPath.Append(",\"RUNTIME_MACROS,\"\"");

                    if (pFeatDsList.Count > 1)
                    {
                        strFeatDsPath.Append("_EXTRA_DATASETS,\"\"\"\"");

                        for (int i = 1; i < pFeatDsList.Count; i++)
                        {
                            if (pFeatDsList[i].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                            {
                                strFeatDsPath.Append("\"\"\"\"\"\"\"\"" + pFeatDsList[i] + "\"\"\"\"\"\"\"\"");
                            }
                            else
                            {
                                strFeatDsPath.Append(pFeatDsList[i]);
                            }

                            if (i < pFeatDsList.Count - 1)
                            {
                                strFeatDsPath.Append(",");
                            }
                        }
                        strFeatDsPath.Append("\"\"\"\",");
                    }

                    strFeatDsPath.Append("_MERGE_SCHEMAS,YES\"\",META_MACROS,,METAFILE,GEODATABASE_FILE,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true\"");
                }
                else if (pFeatDsList[0].EndsWith(".mdb"))
                {
                    //QuickImport GEODATABASE_MDB,"D:\Program Files\规划信息中心\玉环2.mdb","RUNTIME_MACROS,""_IN_FORMAT_NAME,ACCESS,_GEODBInWhereClause,,_GEODBInMINX,0,_GEODBInMINY,0,_GEODBInMAXX,0,_GEODBInMAXY,0,_GEODBInCLIP,no,GEODATABASE_MDB_USE_ENVELOPE,no,_TRANSLATE_SPATIAL_DATA_ONLY,no,_GEODBInResolveDomains,no,_GEODBInResolveSubtypeNames,yes,_GEODBInIgnoreNetworkInfo,no,_GEODBInSplitComplexEdges,no,_GEODBInSplitMultiPartAnnos,no,TABLELIST,,_EXTRA_DATASETS,""""""""""""D:\Program Files\规划信息中心\玉环.mdb"""""""""""",_MERGE_SCHEMAS,YES"",META_MACROS,""Source_IN_FORMAT_NAME,ACCESS,Source_GEODBInWhereClause,,Source_GEODBInMINX,0,Source_GEODBInMINY,0,Source_GEODBInMAXX,0,Source_GEODBInMAXY,0,Source_GEODBInCLIP,no,Source_TRANSLATE_SPATIAL_DATA_ONLY,no,Source_GEODBInResolveDomains,no,Source_GEODBInResolveSubtypeNames,yes,Source_GEODBInIgnoreNetworkInfo,no,Source_GEODBInSplitComplexEdges,no,Source_GEODBInSplitMultiPartAnnos,no"",METAFILE,GEODATABASE_MDB,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" "D:\Program Files\规划信息中心\玉环2.gdb"
                    if (pFeatDsList[0].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                    {
                        strFeatDsPath.Append("GEODATABASE_MDB,\"" + pFeatDsList[0] + "\"");
                    }
                    else
                    {
                        strFeatDsPath.Append("GEODATABASE_MDB," + pFeatDsList[0]);
                    }

                    strFeatDsPath.Append(",\"RUNTIME_MACROS,\"\"_IN_FORMAT_NAME,ACCESS,_GEODBInWhereClause,,_GEODBInMINX,0,_GEODBInMINY,0,_GEODBInMAXX,0,_GEODBInMAXY,0,_GEODBInCLIP,no,GEODATABASE_MDB_USE_ENVELOPE,no,_TRANSLATE_SPATIAL_DATA_ONLY,no,_GEODBInResolveDomains,no,_GEODBInResolveSubtypeNames,yes,_GEODBInIgnoreNetworkInfo,no,_GEODBInSplitComplexEdges,no,_GEODBInSplitMultiPartAnnos,no,TABLELIST,,");

                    if (pFeatDsList.Count > 1)
                    {
                        strFeatDsPath.Append("_EXTRA_DATASETS,\"\"\"\"");

                        for (int i = 1; i < pFeatDsList.Count; i++)
                        {
                            if (pFeatDsList[i].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                            {
                                strFeatDsPath.Append("\"\"\"\"\"\"\"\"" + pFeatDsList[i] + "\"\"\"\"\"\"\"\"");
                            }
                            else
                            {
                                strFeatDsPath.Append(pFeatDsList[i]);
                            }

                            if (i < pFeatDsList.Count - 1)
                            {
                                strFeatDsPath.Append(",");
                            }
                        }
                        strFeatDsPath.Append("\"\"\"\",");
                    }

                    strFeatDsPath.Append("_MERGE_SCHEMAS,YES\"\",META_MACROS,,METAFILE,GEODATABASE_MDB,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true\"");
                }
                else if (pFeatDsList[0].EndsWith(".shp"))
                {
                    //QuickImport SHAPE,D:\地名处理\全省行政村\地名自然村庄（省库）.shp,"RUNTIME_MACROS,""_EXTRA_DATASETS,D:\地名处理\全省行政村\全省行政村.shp,_MERGE_SCHEMAS,YES"",META_MACROS,,METAFILE,SHAPE,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" E:\shape\bbb
                    //QuickImport SHAPE,"D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表1000.shp","RUNTIME_MACROS,""_EXTRA_DATASETS,""""""""""""D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表2000.shp"""""""",""""""""D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表5000.shp"""""""",""""""""D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表10000.shp"""""""""""",_MERGE_SCHEMAS,YES"",META_MACROS,,METAFILE,SHAPE,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true" "D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表.gdb"
                    //QuickImport SHAPE,"D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表2000.shp","RUNTIME_MACROS,""_EXTRA_DATASETS,""""""""""""D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表5000.shp"""""""",""""""""D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\结合表10000.shp"""""""",""""""""D:\Program Files\规划信息中心\绍兴市规划地理信息系统\Data\      市界.shp"""""""""""",_MERGE_SCHEMAS,YES"",META_MACROS,,METAFILE,SHAPE,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true"
                    if (pFeatDsList[0].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                    {
                        strFeatDsPath.Append("SHAPE,\"" + pFeatDsList[0] + "\"");
                    }
                    else
                    {
                        strFeatDsPath.Append("SHAPE," + pFeatDsList[0]);
                    }

                    strFeatDsPath.Append(",\"RUNTIME_MACROS,\"\"");

                    if (pFeatDsList.Count > 1)
                    {
                        strFeatDsPath.Append("_EXTRA_DATASETS,\"\"\"\"");

                        for (int i = 1; i < pFeatDsList.Count; i++)
                        {
                            if (pFeatDsList[i].IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
                            {
                                strFeatDsPath.Append("\"\"\"\"\"\"\"\"" + pFeatDsList[i] + "\"\"\"\"\"\"\"\"");
                            }
                            else
                            {
                                strFeatDsPath.Append(pFeatDsList[i]);
                            }

                            if (i < pFeatDsList.Count - 1)
                            {
                                strFeatDsPath.Append(",");
                            }
                        }

                        strFeatDsPath.Append("\"\"\"\",");
                    }

                    strFeatDsPath.Append("_MERGE_SCHEMAS,YES\"\",META_MACROS,,METAFILE,SHAPE,COORDSYS,,IDLIST,,__FME_DATASET_IS_SOURCE__,true\"");
                }
                else
                {
                    return;
                }

                pQuickImportTool.Input = strFeatDsPath.ToString();

                bool bln = RunTool(GP, pQuickImportTool, null);
                if (bln)
                {
                    for (int i = 0; i < pFeatDsList.Count; i++)
                    {
                        LogHelper.WriteLog("数据：" + pFeatDsList[i] + " 转换成功!");
                    }
                    MsgHelper.ShowInfomationMsgbox("数据转换成功!");
                }
                else
                {
                    for (int i = 0; i < pFeatDsList.Count; i++)
                    {
                        LogHelper.WriteLog("数据：" + pFeatDsList[i] + " 转换失败!");
                    }
                    MsgHelper.ShowInfomationMsgbox("数据转换失败!");
                }

                System.Windows.Forms.Application.DoEvents();
            }
            catch (System.Exception ex)
            {
                MsgHelper.ShowErrorMsgbox("转换失败:" + ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btn_SelectData_Click(object sender, EventArgs e)
        {

            openDataDialog1.MultiSelect = true;
            openDataDialog1.ShowDialog(this);


            //try
            //{
            //    //if (combo_SrcType.SelectedIndex == 0)
            //    {
            //        OpenDataDialog dialog = new OpenDataDialog();
            //        dialog.AllowMultiSelect = true;
            //        dialog.RestoreLocation = false;                    
            //        IGWObjectFilter pFilter3 = new GWFilterFeatureClasses();
            //        dialog.AddFilter(pFilter3, true);
            //        IGWObjectFilter pFilter4 = new GWFilterMiffiles();
            //        dialog.AddFilter(pFilter4, false);

            //        dialog.Title = "选择矢量数据";
            //        if ((dialog.ShowDialog() == DialogResult.OK) && (dialog.Selection.Count != 0))
            //        {
            //            IGWObject obj2 = dialog.Selection[0];
            //            if (dialog.Filter is GWFilterMiffiles)
            //            {
            //                for (int i = 0; i < dialog.Selection.Count; i++)
            //                {
            //                    obj2 = dialog.Selection[i];

            //                    if (obj2.Category == enumObjectCategory.Miffile)
            //                    {
            //                        #region Mif数据名进行解析
            //                        string DsPath = obj2.FullName;
            //                        bool bAdd = false;

            //                        if (DsPath.IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
            //                        {
            //                            bAdd = true;
            //                        }

            //                        string FileName = DsPath.Substring(DsPath.LastIndexOf('\\'));
            //                        string FileTitle = FileName.Substring(0, FileName.LastIndexOf('.'));
            //                        StreamReader sr = File.OpenText(DsPath);
            //                        string str, strType = "";
            //                        while (sr.EndOfStream == false)
            //                        {
            //                            str = sr.ReadLine();
            //                            if (str == "DATA")
            //                            {
            //                                break;
            //                            }
            //                        }

            //                        if (sr.EndOfStream == false)
            //                        {
            //                            strType = sr.ReadLine();
            //                        }
            //                        sr.Close();

            //                        if (strType.StartsWith("POINT"))
            //                        {
            //                            DsPath = DsPath + FileTitle + " Point";
            //                        }
            //                        else if (strType.StartsWith("PLINE"))
            //                        {
            //                            DsPath = DsPath + FileTitle + " Line";
            //                        }
            //                        else if (strType.StartsWith("TEXT"))
            //                        {
            //                            DsPath = DsPath + FileTitle + " Text";
            //                        }
            //                        else if (strType.StartsWith("REGION"))
            //                        {
            //                            DsPath = DsPath + FileTitle + " Polygon";
            //                        }
            //                        else if (strType.StartsWith("COLLECTION"))
            //                        {
            //                            DsPath = DsPath + FileTitle + " Collection";
            //                        }
            //                        else
            //                        {
            //                            continue;
            //                        }
            //                        #endregion

            //                        if (bAdd)
            //                        {
            //                            DsPath = "'" + DsPath + "'";
            //                        }

            //                        if (DsPath.Trim().Length > 3)
            //                        {
            //                            pFeatClsList.Add(DsPath);
            //                            listInputData.Items.Add(DsPath);
            //                        }
            //                    }
            //                }
            //            }
            //            else
            //            {
            //                IDataset dataset = ((IName)obj2.DatasetName).Open() as IDataset;
            //                if (dataset is IFeatureClass)
            //                {
            //                    {
            //                        string DsPath = GetGpDsPath((IFeatureClass)dataset);
            //                        if (DsPath.IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
            //                        {
            //                            //MessageBox.Show("输入数据[" + DsPath + "]数据名或路径中不能包含空格，请先修改数据名或路径！");
            //                            DsPath = "'" + DsPath + "'";
            //                        }

            //                        if (DsPath.Trim().Length > 3)
            //                        {
            //                            pFeatClsList.Add(DsPath);
            //                            listInputData.Items.Add(DsPath);
            //                        }
            //                    }

            //                    for (int i = 1; i < dialog.Selection.Count; i++)
            //                    {
            //                        obj2 = dialog.Selection[i];
            //                        dataset = ((IName)obj2.DatasetName).Open() as IDataset;
            //                        if (dataset is IFeatureClass)
            //                        {
            //                            string DsPath = GetGpDsPath((IFeatureClass)dataset);
            //                            if (DsPath.IndexOf(" ") > 0) //输入数据字符串中， 如果包含空格，则需要两端加单引号
            //                            {
            //                                //MessageBox.Show("输入数据[" + DsPath + "]数据名或路径中不能包含空格，请先修改数据名或路径！");
            //                                DsPath = "'" + DsPath + "'";
            //                            }

            //                            if (DsPath.Trim().Length > 3)
            //                            {
            //                                pFeatClsList.Add(DsPath);
            //                                listInputData.Items.Add(DsPath);
            //                            }
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }
            //    /*else 
            //    {
            //        //MDB SHP MIF CAD DGN
            //        OpenFileDialog cadfiledlg = new OpenFileDialog();
            //        cadfiledlg.Multiselect = true;
            //        if (combo_SrcType.SelectedIndex == 1)
            //        {
            //            cadfiledlg.Title = "选择MDB文件";
            //            cadfiledlg.Filter = "个人空间数据库 MDB文件(*.mdb)|*.mdb";
            //        }
            //        else if (combo_SrcType.SelectedIndex == 2)
            //        {
            //            cadfiledlg.Title = "选择Shape文件";
            //            cadfiledlg.Filter = "Shape文件(*.shp)|*.shp";
            //        }
            //        else if (combo_SrcType.SelectedIndex == 3)
            //        {
            //            cadfiledlg.Title = "选择MIF文件";
            //            cadfiledlg.Filter = "MapInfo Mif文件(*.mif)|*.mif";
            //        }
            //        else if (combo_SrcType.SelectedIndex == 4)
            //        {
            //            cadfiledlg.Title = "选择CAD文件";
            //            cadfiledlg.Filter = "AutoCAD DWG文件(*.dwg)|*.dwg|AutoCAD DXF文件(*.dxf)|*.dxf";
            //        }
            //        else if (combo_SrcType.SelectedIndex == 5)
            //        {
            //            cadfiledlg.Title = "选择DGN文件";
            //            cadfiledlg.Filter = "Microstation DGN文件(*.dgn)|*.dgn";
            //        }

            //        if (cadfiledlg.ShowDialog() == DialogResult.OK)
            //        {
            //            for (int i = 0; i < cadfiledlg.FileNames.Length; i++)
            //            {
            //                pFeatDsList.Add(cadfiledlg.FileNames[i]);
            //                listInputData.Items.Add(cadfiledlg.FileNames[i]);
            //            }
            //        }                    
            //    }*/
            //}
            //catch (Exception ex)
            //{
            //    MsgHelper.ShowErrorMsgbox("选择数据对话框出错，出错信息为:" + ex.Message);
            //}

        }

        private void FrmDlgDataConvert_Load(object sender, EventArgs e)
        {
            //combo_SrcType.SelectedIndex = 0;
            combo_SaveFormat.SelectedIndex = 0;            
            openDataDialog1.OnOkClick = new EventHandler(CmdAddDataOk_Click);
        }

        public List<IDataNode> DataNodeList
        {
            get { return m_DataNodes; }
        }

        private void CmdAddDataOk_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                if (m_DataNodes == null)
                {
                    m_DataNodes = openDataDialog1.GetSelectNode<IDataNode>();
                }
                else
                {
                    m_DataNodes.AddRange(openDataDialog1.GetSelectNode<IDataNode>());
                }


                //                            pFeatClsList.Add(DsPath);
                //                            listInputData.Items.Add(DsPath);
                listInputData.Items.Clear();

                if (SelectDataOk != null)
                {
                    SelectDataOk.Invoke(DataNodeList);
                }

                foreach (IDataNode dataNode in m_DataNodes)
                {
                    //if (esriDatasetTypeFilters != null)
                    //{
                    //    if (!esriDatasetTypeFilters.Contains(dataNode.WorkspaceType))
                    //    {
                    //        MsgHelper.ShowWarningMsgbox("[" + dataNode.Name + "]不是当前有效的数据格式。");
                    //        m_DataNodes.Remove(dataNode);
                    //        continue;
                    //    }
                    //}
                    pFeatDsList.Add("'" + dataNode.Path + "'");
                    listInputData.Items.Add(dataNode.Path);

                    openDataDialog1.Hide();
                }
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private bool RunTool(Geoprocessor geoprocessor, IGPProcess process, ESRI.ArcGIS.esriSystem.ITrackCancel TC)
        {
            bool blnResult = false;
            // Set the overwrite output option to true
            geoprocessor.OverwriteOutput = true;
            IGeoProcessorResult objResult = null;

            // Execute the tool            
            try
            {
                objResult = geoprocessor.Execute(process, null) as IGeoProcessorResult;
                System.Windows.Forms.Application.DoEvents();
                if (objResult != null)
                {
                    if (objResult.Status == esriJobStatus.esriJobSucceeded)
                    {
                        blnResult = true;
                    }
                }
                else
                {
                    if (geoprocessor.MessageCount == 0)
                    {
                        blnResult = true;
                    }
                    else
                    {
                        blnResult = false;
                    }
                }

                //无论是否成功，都把GP的日志输出
                //if (!blnResult)
                {
                    OutputMessages(geoprocessor);
                }
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                OutputMessages(geoprocessor);
            }
            finally
            {
            }
            return blnResult;
        }

        private void OutputMessages(Geoprocessor gp)
        {
            if (gp.MessageCount > 0)
            {
                for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
                {
                    LogHelper.WriteLog(gp.GetMessage(Count));
                }
            }
            gp.ClearMessages();
        }

        private string GetGpDsPath(IFeatureClass pFcls)
        {
            IDataset pDst = pFcls as IDataset;
            string strFclsPath = "";
            string strInput;
            switch (pDst.Workspace.Type)
            {
                case esriWorkspaceType.esriFileSystemWorkspace:
                    strFclsPath = pDst.Workspace.PathName;
                    if (pDst.Category == "Shapefile Feature Class")
                    {
                        strInput = strFclsPath + "\\" + pDst.Name + ".shp";
                    }
                    else if ((pDst.Category == "CAD Point Feature Class") || pDst.Category == "CAD Polyline Feature Class" || pDst.Category == "CAD Polygon Feature Class" || pDst.Category == "CAD Annotation Feature Class" || pDst.Category == "CAD MultiPatch Feature Class")
                    {
                        strInput = strFclsPath + "\\" + pFcls.FeatureDataset.Name + "\\" + pDst.Name;
                    }
                    else
                    {
                        strInput = strFclsPath + "\\" + pDst.Name + "\\" + pFcls.AliasName;
                    }
                    break;
                case esriWorkspaceType.esriLocalDatabaseWorkspace:
                    strFclsPath = pDst.Workspace.PathName;
                    if (pFcls.FeatureDataset != null)
                    {
                        strInput = strFclsPath + "\\" + pFcls.FeatureDataset.Name + "\\" + pDst.Name;
                    }
                    else
                    {
                        strInput = strFclsPath + "\\" + pDst.Name;
                    }
                    break;
                case esriWorkspaceType.esriRemoteDatabaseWorkspace:
                    string strSdeFile = System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location) + "\\tempconvert.sde";
                    if (!File.Exists(strSdeFile))
                    {
                        IWorkspaceFactory pWksFac = new SdeWorkspaceFactoryClass();
                        pWksFac.Create(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location), "tempconvert.sde", pDst.Workspace.ConnectionProperties, 0);
                    }
                    //strSdeFile = "Database Connections\\Connection to " + pDst.Workspace.ConnectionProperties.GetProperty("Server").ToString() + ".sde";

                    if (pFcls.FeatureDataset != null)
                    {
                        strInput = strSdeFile + "\\" + pFcls.FeatureDataset.Name + "\\" + pDst.Name;
                    }
                    else
                    {
                        strInput = strSdeFile + "\\" + pDst.Name;
                    }
                    break;
                default:
                    {
                        return "";
                    }
            }
            return strInput;
        }

        private void combo_SaveFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (combo_SaveFormat.SelectedIndex == 4) //|| (combo_SaveFormat.SelectedIndex == 5))
                btn_Setting.Visible = true;
            else
                btn_Setting.Visible = false;
            txtExportPath.Text = "";
        }

        private void btn_Setting_Click(object sender, EventArgs e)
        {
            FrmCADOutputSettings pCADSetting = new FrmCADOutputSettings(combo_SaveFormat.Text);
            if (pCADSetting.ShowDialog() == DialogResult.OK)
            {
                CADFileVersion = pCADSetting.combo_Versions.Text;
                CADTemplateFile = pCADSetting.txt_TemplateFile.Text;
            }
        }

        private void btn_DelInput_Click(object sender, EventArgs e)
        {
            if (listInputData.SelectedIndices.Count <= 0)
            {
                return;
            }

            for (int i = listInputData.SelectedIndices.Count - 1; i >= 0; i--)
            {
                int index = listInputData.SelectedIndices[i];
                listInputData.Items.RemoveAt(index);
                m_DataNodes.Remove(m_DataNodes[index]);

                if (pFeatClsList.Count > 0)
                    pFeatClsList.RemoveAt(index);
                else if (pFeatDsList.Count > 0)
                    pFeatDsList.RemoveAt(index);
            }
            if (SelectDataOk != null)
            {
                SelectDataOk.Invoke(m_DataNodes);
            }



            //List<int> selitems = new List<int>();
            //for (int i = 0; i < listInputData.SelectedIndices.Count; i++)
            //{
            //    selitems.Add(listInputData.SelectedIndices[i]);
            //}

            //for (int i = selitems.Count - 1; i > -1; i--)
            //{
            //    listInputData.Items.RemoveAt(selitems[i]);
            //    if (pFeatClsList.Count > 0)
            //        pFeatClsList.RemoveAt(selitems[i]);
            //    else if (pFeatDsList.Count > 0)
            //        pFeatDsList.RemoveAt(selitems[i]);
            //}
        }

        private void combo_SrcType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (combo_SrcType.SelectedIndex == 0)
            {
                if (pFeatDsList.Count > 0)
                {
                    pFeatDsList.Clear();
                    listInputData.Items.Clear();
                }
                
                combo_SaveFormat.Enabled = true;                
            }
            /*else
            {
                if (pFeatClsList.Count > 0)
                {
                    pFeatClsList.Clear();
                    listInputData.Items.Clear();
                }

                combo_SaveFormat.SelectedIndex = 0;
                combo_SaveFormat.Enabled = false;
            }*/
        }
    }
}
